<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title></title>
		<link rel="stylesheet" href="js/bootstrap/css/bootstrap.css" />
		<link rel="stylesheet" href="js/datetimepicker/jquery.datetimepicker.css" />
	</head>
	<body>

		<div class="container">
		
			<h2 class="page-header">修改课程信息</h2>
			
			<form id="form1" class="form-horizontal">
				<div class="form-group">
					<label for="" class="col-sm-2" style="color: white;">课程名称</label>
					<div class="col-sm-8">
						<input type="text" id="sourseName" name="sourseName" placeholder="请输入课程名称" class="form-control" />
					</div>
				</div>
				<div class="form-group">
					<label for="" class="col-sm-2" style="color: white;">所属职业</label>
					<div class="col-sm-8">
						<select name="job.jobId" id="jobId" class="form-control">
							<option value="">请选择课程所属职业</option>													
						</select>
					</div>
				</div>
				<div class="form-group">
					<label for="" class="col-sm-2" style="color: white;">课程简介</label>
					<div class="col-sm-8">
						<input type="text" id="sourseIntro" name="sourseIntro" placeholder="请输入课程简介" class="form-control" />
					</div>
				</div>
			
				<div class="form-group">
					<div class="col-sm-offset-2 col-sm-10">
						<input type="hidden" id="sourseId" name="sourseId" />
						<input type="button" value="修改" id="updateBtn" class="btn btn-success" />
						<input type="button" value="取消" class="btn btn-warning" onclick="window.parent.layer.closeAll()" />
					</div>
				</div>
				
			</form>
		</div>
			
		<script type="text/javascript" src="js/jquery.js"></script>
		<script type="text/javascript" src="js/global.js"></script>
		<script type="text/javascript" src="js/bootstrap/js/bootstrap.js"></script>
		<script type="text/javascript" src="js/layer/layer.js"></script>
		<script type="text/javascript" src="js/datetimepicker/jquery.datetimepicker.js"></script>
		<script type="text/javascript" src="js/param.js"></script>
		<script>
		
			$(function() {
				
				//动态生成职务列表框
				$.ajax({
					url:baseUrl + '/job/query',
					type:'GET',
					dataType:'json'				
				})
				.done(function(data){				
					$.each(data, function(index,item) {					
						var opt = '<option value="' + item.jobId + '">' + item.jobName + '</option>';
						$('#jobId').append(opt);
					});					
				})
				.fail(function(xhr,status,text){
					layer.msg('职务列表请求失败');				
				});
				
				//获得员工信息
				var sourseId = getParam('sourseId');
			
				//获得员工数据的数据模型中数组下标
				var index = getParam('index');
			
				$.getJSON(baseUrl + '/sourse/get', {
						sourseId: sourseId
					}, function(data) {
						$('#sourseName').val(data.sourseName);
						$('#jobId').val(data.job.jobId);
						$('#sourseIntro').val(data.sourseIntro);
						$('#sourseId').val(data.sourseId);
			
					})
					.error(function() {
						layer.msg('网络请求失败');
					});
						
				/*验证表单函数*/
				function checkForm() {
					
					//文件描述验证
					var sourseIntro = $('#sourseIntro');
					if (sourseIntro.val() == '' || sourseIntro.val().length > 2000) {
						layer.msg('图片描述不能够为空 并且最多2000个字符');
						$('#sourseIntro').focus();
						return false;
					}
					return true;
				}
				//上传按钮的单击事件
				$('#updateBtn').click(function() {
			
					if (!checkForm()) {
						return;
					}
					var params = $('#form1').serialize();
					alert(params);
					console.log(params);
					$.post(baseUrl + '/sourse/updateMessage', params, function(data) {
							layer.msg('修改课程信息成功');
	
							//修改前端员工数据
							var sourse = window.parent.vue.sourseData[index];
	
							sourse.sourseId = sourseId;
							sourse.sourseName = $('#sourseName').val();
							sourse.sourseIntro = $('#sourseIntro').val();
							sourse.job.jobName = $('#jobId option:selected').text();
	
							setTimeout(function() {
								window.parent.layer.closeAll();
							}, 500);
						})
						.error(function() {
							layer.msg('修改课程信息请求失败');
						});
			
				});
			});
		</script>

	<body>
<html>
